/* $Id: scripts.prg,v 1.0 2008/11/25 23:32:20 riztan Exp $*/
/*
	Copyright © 2008  Riztan Gutierrez <riztang@gmail.com>

   Este programa es software libre: usted puede redistribuirlo y/o modificarlo 
   conforme a los términos de la Licencia Pública General de GNU publicada por
   la Fundación para el Software Libre, ya sea la versión 3 de esta Licencia o 
   (a su elección) cualquier versión posterior.

   Este programa se distribuye con el deseo de que le resulte útil, pero 
   SIN GARANTÍAS DE NINGÚN TIPO; ni siquiera con las garantías implícitas de
   COMERCIABILIDAD o APTITUD PARA UN PROPÓSITO DETERMINADO. Para más información, 
   consulte la Licencia Pública General de GNU.

   http://www.gnu.org/licenses/
*/

#include "gclass.ch"
#include "proandsys.ch"

/** \file scripts.prg.
 *  \brief Este Archivo Aloja las Funciones de Edicion y Almacenaje de 
 *  scripts del proyecto Tepuy.
 *  \author Riztan Gutierrez. riztan@gmail.com
 *  \date 2008
*/


#define GTK_WRAP_WORD      2
#define GTK_TEXT_DIR_RTL   2
#define PANGO_STYLE_ITALIC 2
// #define PANGO_SCALE 1024

Function TextView()
    Local cText := "Power of TextView" + CRLF, oWnd, oTextView, oScroll, oBox, oBtn

    DEFINE WINDOW oWnd TITLE "Oh!! TextView POWER"  SIZE 500,500
      DEFINE BOX oBox OF oWnd VERTICAL
        DEFINE BUTTON oBtn TEXT "Insert" OF oBox ACTION ( Create_Text( oTextView, oScroll ), oBtn:Disable() )
        
        DEFINE SCROLLEDWINDOW oScroll OF oBox CONTAINER
          DEFINE TEXTVIEW oTextView VAR cText OF oScroll CONTAINER
        
    ACTIVATE WINDOW oWnd CENTER

RETURN NIL    
    
STATIC FUNCTION Create_Text( oTextView , oScroll )
    Local oFile := gTextFile():New( "./xbscripts/test.xbs", "R" )
    Local nWhere := 1
    Local aStart := Array( 14 ),oImage, j, cLine

    // Example insert from AT_CURSOR and source file txt
    oFile:Goto( 1 )
    while !oFile:lEoF 
       cLine := oFile:Read() 
       oTextView:Insert( cLine )
       oFile:Goto( ++nWhere )
    end while
    
    oFile:Close()


/*
    // Ok, i put my image in TextView ;-)
    oTextView:oBuffer:GetIterAtOffSet( aStart, -1 ) 
    DEFINE IMAGE oImage FILE "../../../images/gnome-foot.png" LOAD
    For j := 1  To 10
        oTextView:Insert_Pixbuf( aStart, oImage )
    Next
    
    // Ops, new line ;-)
    oTextView:Insert( CRLF )
     
    // Ah! Tags examples....
    oTextView:oBuffer:GetIterAtOffSet( aStart, -1 ) 
    oTextView:CreateTag( "heading", { "weight", 700,;
                                      "size", 10*PANGO_SCALE,;
                                      "justification", GTK_JUSTIFY_CENTER } )
    oTextView:Insert_Tag( "(c)2006 Rafa Carmona" , "heading", aStart )
    // New image
    DEFINE IMAGE oImage FILE "../../images/rafa2.jpg" LOAD
    oTextView:Insert_Pixbuf( aStart, oImage )
     
    // Ops, new line ;-)
    oTextView:Insert( CRLF )
     
    // Eh!, you localicate you position with GetIterAtOffset
    oTextView:oBuffer:GetIterAtOffSet( aStart, -1 ) 
    DEFINE IMAGE oImage FILE "../../images/gnome-gsame.png" LOAD
    For j := 1  To 10
        oTextView:Insert_Pixbuf( aStart, oImage )
    Next
    
    // Ops, new line ;-)
    oTextView:Insert( CRLF )
    oTextView:oBuffer:GetIterAtOffSet( aStart, -1 ) 
    oTextView:CreateTag( "blue_fore",{ "foreground", "blue" } )
    oTextView:CreateTag( "red_back", { "background", "red" } )

    oTextView:CreateTag( "blue_and_red", { "background", "red",  "foreground", "blue",;
                                           "justification", GTK_JUSTIFY_CENTER,;
                                           "weight", 700, "size", 14*PANGO_SCALE } )

    oTextView:Insert_Tag( "This text is blue foreground , yes..." , "blue_fore", aStart )
    oTextView:Insert_Tag( "...and this text is red background , yes..."+ CRLF + CRLF,;
                          "red_back", aStart )
    oTextView:Insert_Tag( "...Oh!! this text is TOTAL, yes..."+CRLF+CRLF ,;
                          "blue_and_red", aStart )
  
    // Put Code source in TexView.
    oTextView:CreateTag( "window", { "background", "yellow",;
                                     "foreground", "blue",;
                                     "left_margin", 20,;
                                     "right_margin", 20 } )
    oTextView:CreateTag( "window_back", { "left_margin", 20, "right_margin", 20 } )
    oTextView:CreateTag( "comment", { "style", PANGO_STYLE_ITALIC,;
                                      "left_margin", 20,;
                                      "right_margin", 20,;
                                      "foreground", "darkred"  } )
     
    oTextView:Insert( "Well, this example you view personality your MEMOS under [x]Harbour" +CRLF )
    oTextView:Insert( "Code source from direct file: " + CRLF + CRLF)

    oFile := gTextFile():New( "textview.prg", "R" )
    nWhere := 1

    oTextView:oBuffer:GetIterAtOffSet( aStart, -1 ) 
    oFile:Goto( 1 )
    while !oFile:lEoF 
       cLine := oFile:Read() 
       DO CASE
          CASE "WINDOW" $ cLine
               oTextView:Insert_Tag( cLine , "window", aStart )
          CASE "//" $ cLine
               DEFINE IMAGE oImage FILE "../../images/header.png" LOAD
              oTextView:Insert_Pixbuf( aStart, oImage )
              oTextView:Insert_Tag( cLine , "comment", aStart )
          OTHERWISE
                oTextView:Insert_Tag( cLine , "window_back", aStart )
       ENDCASE
       oFile:Goto( ++nWhere )
    end while
    oFile:Close()
*/
    
    //MsgInfo( cValtoChar( GTK_TEXT_BUFFER_GET_LINE_COUNT( oTextView:oBuffer:pWidget ) ) )
Return nil 


/** \brief Visualizar texto con GtkSourceView2
 *
 */
function ScrView( cMime )

  local hWnd, hView, scrolled

  DEFAULT cMime := "text/x-prg"  // Por defecto, sintaxis de xHarbour

/* Ventana */
   hWnd := gtk_window_new( GTK_WINDOW_TOPLEVEL )
   Gtk_Signal_Connect( hWnd, "delete-event", {|| Salida_aqui() } )  // Cuando se mata la aplicacion

/* Method Activate */
   gtk_window_set_title( hWnd, "Test GtkSourceView [x]Harbour" )
   gtk_window_set_position( hWnd, GTK_WIN_POS_CENTER )
   gtk_window_set_default_size( hWnd, 500, 350 )
   
   
   scrolled = gtk_scrolled_window_new(NIL, NIL )
   gtk_container_set_border_width( scrolled, 10 )
   gtk_scrolled_window_set_policy( scrolled,;
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS )

   gtk_container_add ( hWnd, scrolled )
   gtk_widget_show( scrolled )

   hView := HB_GTK_SOURCE_CREATE_NEW( cMime ) // gtk_source_view_new( )

   gtk_source_view_set_show_line_numbers( hView, .T. )
   gtk_container_add ( scrolled, hView)
   gtk_widget_show( hView )
   
   gtk_widget_show( hWnd )

   gtk_Main()

return NIL

//--------------------------------------------------------------------------//
//Salida controlada del programa.
Function Salida_aqui( widget )
   gtk_main_quit()
Return .F.  // Salimos y matamos la aplicacion.

